package com.summer.data.connection.sessioninterface;

import com.summer.data.Jql;
import com.summer.data.Jsql;
import com.summer.data.connection.PageInfoHolder;
import com.summer.data.dialect.Dialect;
import com.summer.data.rs.Extractor;
import com.summer.data.rs.datatype.MapPage;
import com.summer.data.rs.datatype.ObjectPage;
import com.summer.data.rs.datatype.PageInfo;

import java.util.List;
import java.util.Map;

/**
 * 基于 Jql 的操作接口
 * @author 345480567@qq.com
 */
public interface JqlSessionInterface extends JsqlSessionInterface {

    default List<Map<String, Object>> query(Jql jql) {
        Dialect dialect = getDialect();
        Jsql jsql = jql.buildJsql(dialect);
        return query(jsql);
    }

    default <T> List<T> query(Jql jql, Class<T> clazz) {
        Dialect dialect = getDialect();
        Jsql jsql = jql.buildJsql(dialect);
        return query(jsql, clazz);
    }

    default Map<String, Object> first(Jql jql) {
        Dialect dialect = getDialect();
        Jsql jsql = jql.buildJsql(dialect);
        return first(jsql);
    }

    default <T> T first(Jql jql, Class<T> clazz) {
        Dialect dialect = getDialect();
        Jsql jsql = jql.buildJsql(dialect);
        return first(jsql, clazz);
    }

    default Map<String, Object> find(Jql jql) {
        Dialect dialect = getDialect();
        Jsql jsql = jql.buildJsql(dialect);
        return find(jsql);
    }

    default <T> T find(Jql jql, Class<T> clazz) {
        Dialect dialect = getDialect();
        Jsql jsql = jql.buildJsql(dialect);
        return find(jsql, clazz);
    }

    default <T> T query(Jql jql, Extractor<T> extractor) {
        Dialect dialect = getDialect();
        Jsql jsql = jql.buildJsql(dialect);
        return query(jsql, extractor);
    }

    default Integer count(Jql jql) {
        Dialect dialect = getDialect();
        Jsql jsql = jql.buildJsql(dialect);
        return count(jsql);
    }

    default MapPage pageQuery(Jql jql) {
        Dialect dialect = getDialect();
        Jsql jsql = jql.buildJsql(dialect);
        return pageQuery(jsql);
    }

    default <T> ObjectPage<T> pageQuery(Jql jql, Class<T> clazz) {
        Dialect dialect = getDialect();
        Jsql jsql = jql.buildJsql(dialect);
        return pageQuery(jsql, clazz);
    }

}
